﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XLB.ExtensionMethod.Aggregate
{
    /// <summary>
    /// list集合操作类
    /// </summary>
    public class ListHelper
    {
        /// <summary>
        /// 获取两个集合的差集(list1 差 list2)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list1"></param>
        /// <param name="list2"></param>
        /// <returns></returns>
        public List<T> SetDifferenceSet<T>(List<T> list1, List<T> list2)
        {
            return list1.Except(list2).ToList();
        }

        /// <summary>
        /// 获取两个string集合的差集(list1 差 list2)
        /// </summary>
        /// <param name="list1"></param>
        /// <param name="list2"></param>
        /// <returns></returns>
        public List<string> StringSetDifferenceSet(List<string> list1, List<string> list2)
        {
            #region 非空验证
            if (list1 == null)
            {
                return null;
            }
            if (list2 == null)
            {
                return list1;
            }
            #endregion
            List<string> list = new List<string>();
            foreach (var item in list1)
            {
                var templist = list2.Where(u => u == item);
                if (templist.Count() <= 0)
                {
                    list.Add(item);
                }
            }
            return list;
        }

        ///// <summary>
        ///// 交集
        ///// </summary>
        ///// <returns></returns>
        //public List<T> GetIntersection<T>(List<T> list1, List<T> list2)
        //{

        //}

        ///// <summary>
        ///// 并集
        ///// </summary>
        ///// <typeparam name="T"></typeparam>
        ///// <param name="list"></param>
        ///// <returns></returns>
        //public List<T> Union<T>(List<T> list1,List<T> list2)
        //{

        //}
    }
}
